// JavaScript Document
var wzgd=null;//定义定时器对象
var wzts=["点击允许，开启摄像头，将二维码对准摄像头，使您的二维码出现在白框内","由于电脑摄像头像素较低，而且不能自动对焦，因此复杂的二维码需要更靠近摄像头，效果会更好","该功能还在测试修改中","摄像头扫描占用计算机资源比较大，若不需要使用，可以及时关闭"];
var wztspd=false;
window.onload=function(){
	if (window.clipboardData) {  
    }
	else{
	var clip1 = new ZeroClipboard( document.getElementById("d_clip_button"), {
      moviePath: "/camdecord/ZeroClipboard.swf"
     });
     // 复制内容到剪贴板成功后的操作
    clip1.on( 'complete', function(client, args) {
    alert("复制成功!");
} );
}
	}
window.onresize=function(){
	var div=document.getElementById("dialogbg1");
	if(div.style.display=="block"){
	var  newMaskWidth =document.body.scrollWidth;//遮罩层宽度
    var  newMaskHeight =document.body.scrollHeight;//遮罩层高度 
	div.style.width = newMaskWidth + "px";//设置遮罩层宽度
    div.style.height = newMaskHeight + "px";//设置遮罩层高度
	}
	}
function hasFlashPlugin(){
	if(!!navigator.userAgent.match(/MSIE/)){
		try{
			new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			return true;
			}
		catch(ex){
			return false;
			}
		}
	else{
		var swf=navigator.plugins["Shockwave Flash"];
		if(swf){return true;}
		else{return false;}
		}
	}
function djfz(){
	if (window.clipboardData) {  
	    var text=document.getElementById("fe_text");
	    window.clipboardData.clearData();  
        window.clipboardData.setData("Text", text.value);  
        alert("复制成功！") ; 
	}
	}
function addwzts(){
	if(wztspd){
		
		}
	else{
	   var ul1=document.createElement("ul");
	   ul1.className="wzts";
	   ul1.style.marginLeft="600px";
	   ul1.id="wzts";
	   for(var i=0;i<wzts.length;i++){
		   var li=document.createElement("li");
		   li.innerHTML=wzts[i];
		   ul1.appendChild(li);
		   }
	   var camhead=document.getElementById("camera_head");
	   camhead.appendChild(ul1);
	   //wzgdxg();
	}
	}
function wzgdxg(){
    clearInterval(wzgd);
	var speed=10;
	var ul1=document.getElementById("wzts");
	wzgd=setInterval(function(){
		ul1.style.marginLeft=parseInt(ul1.style.marginLeft)-speed+"px";
		},200);
	}
function setCamera(){
	
	cameradialogbg();
	var cameradiv=document.getElementById("camera");
	var camera='';
	if(hasFlashPlugin()){
	if(!!navigator.userAgent.match(/MSIE/)){ //ie浏览器
		camera='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="600" height="450" id="webcam_movie" align="middle"><param name="allowScriptAccess" value="always" /><param name="wmode" value="transparent"> <param name="allowFullScreen" value="false" /><param name="movie" value="/camdecord/cam.swf" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="best" /><param name="bgcolor" value="#ffffff" /><param name="flashvars" value=""/></object>';
		}
	else{
		camera='<embed id="webcam_movie" src="/camdecord/cam.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="600" height="450" name="webcam_movie" align="middle" wmode="transparent" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="" />';
		}
	}
	else{
		 var pageHost = ((document.location.protocol == "https:") ? "https://" : "http://"); 
         camera="<a href='http://www.adobe.com/go/getflashplayer'><img src='" 
                                + pageHost + "www.adobe.com/images/shared/download_buttons/get_flash_player.gif' alt='Get Adobe Flash player' /></a></br><p>您的浏览器未安装flash插件或者已被禁用，请点击图片下载该插件，或者启用您的flash插件</p>" ;

		}
	cameradiv.innerHTML=camera;
    var cameraout=document.getElementById("camera_main");
	//addwzts();
	cameraout.style.display="block";
	}
function getHelp(){
	var helpdiv=document.getElementById("xtsnr");
	helpdiv.style.display=helpdiv.style.display=="block"?"none":"block";
	}
function helpChange(){
	var helpdiv=document.getElementById("xts");
	var whdiv=document.getElementById("whtb");
	whdiv.style.background="url(/camdecord/images/wh.png)";
	helpdiv.style.background="#effcf5";
	}
function helpChange1(){
	var helpdiv=document.getElementById("xts");
	var whdiv=document.getElementById("whtb");
	whdiv.style.background="url(/camdecord/images/wh1.png)";
	helpdiv.style.background="#f2f2f2";
	}
//弹出摄像头时背景颜色
function cameradialogbg(msg){
	/*var div=document.createElement("div");
	div.className="dialogbg1";
	div.id="dialogbg1";
	var pageWidth=document.body.scrollWidth;//遮罩层宽度  
    var pageHeight =document.body.scrollHeight;//遮罩层高度 
	/*if(typeof pageWidth!="number"){
		if(document.compatMode=="CSS1Compat"){
			pageWidth=document.documentElement.scrollWidth;
			pageHeight=document.documentElement.scrollHeight;
			}
		else{
			pageWidth=document.body.scrollWidth;
			pageHeight=document.body.scrollHeight;
			}
		}*/
	/*div.style.height=pageHeight+"px";
	div.style.width=pageWidth+"px";
	document.body.appendChild(div);*/

	var div=document.getElementById("dialogbg1");
	var  newMaskWidth =document.body.scrollWidth;//遮罩层宽度
    var  newMaskHeight =document.body.scrollHeight;//遮罩层高度 
	div.style.width = newMaskWidth + "px";//设置遮罩层宽度
    div.style.height = newMaskHeight + "px";//设置遮罩层高度
    div.style.top = "0px";//设置遮罩层于上边距离
    div.style.left = "0px";//设置遮罩层左边距离
	div.style.display="block";
	}
function jsFlash(msg){
	alert("未检测到摄像头,请接入摄像头再进行尝试");
    CameraRemove();
	}
function resultDiabg(){
	var div=document.createElement("div");
	div.className="dialogbg2";
	div.id="dialogbg2";
	div.style.height=500+"px";
	div.style.width=695+"px";
	document.getElementById("camera_main").appendChild(div);
	}
function resultdialog(msg){
	var text=document.getElementById("fe_text");
	text.value=msg;
	resultDiabg();
	var div=document.getElementById("dhk");
	var div1=document.getElementById("result_content");
	div.style.display="block";
    var regex = "http://(([a-zA-z0-9]|-){1,}\\.){1,}[a-zA-z0-9]{1,}-*";
	if(msg.match(regex)){
	   div1.innerHTML="<a href='"+msg+"'>"+msg+"</a>";
	}
	else{
	   div1.innerHTML=msg; 
		}
    var success = document.getElementById("success");
	var result = document.getElementById('result');
	shide(success,'hide');
	shide(result,'hide');
	}
function JsHello(msg){
	resultdialog(msg);
}
//移除摄像头
function CameraRemove(){
	var cameradiv=document.getElementById("camera_main");
	var flashObj= document.getElementById("webcam_movie");	
	var dialogbg=document.getElementById("dialogbg1");
	dialogbg.style.display="none";
	var camera=document.getElementById("camera");
	cameradiv.style.display="none";
	var ts=document.getElementById("Camera_ts");
    ts.innerHTML="点击允许，开启摄像头";
	flashObj.cameraEnd();
	camera.innerHTML="";
	}
function AllClose(){
	var cameramain=document.getElementById("camera_main");
	var dhkdiv=document.getElementById("dhk");
	var dhkbgdiv=document.getElementById("dialogbg2");
	cameramain.removeChild(dhkbgdiv);
	dhkdiv.style.display="none";
	CameraRemove();
	}
function flashrefuse(msg){
	alert("请点击允许，打开摄像头进行扫描");
	var cameradiv=document.getElementById("camera");
	var camera='';
	if(!!navigator.userAgent.match(/MSIE/)){ //ie浏览器
		camera='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="600" height="450" id="webcam_movie" align="middle"><param name="allowScriptAccess" value="always" /><param name="wmode" value="transparent"> <param name="allowFullScreen" value="false" /><param name="movie" value="/camdecord/cam.swf" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="best" /><param name="bgcolor" value="#ffffff" /><param name="flashvars" value=""/></object>';
		}
	else{
		camera='<embed id="webcam_movie" src="/camdecord/cam.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="600" height="450" name="webcam_movie" align="middle" wmode="transparent" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="" />';
		}
	cameradiv.innerHTML=camera;
	}
function flashOk(msg){
	var ts=document.getElementById("Camera_ts");
	ts.innerHTML="将二维码垂直对准摄像头，使您的二维码出现在白框内";
}
function CameraContinue(){
	var cameramain=document.getElementById("camera_main");
	var dhkdiv=document.getElementById("dhk");
	var dhkbgdiv=document.getElementById("dialogbg2");
	cameramain.removeChild(dhkbgdiv);
	dhkdiv.style.display="none";
	var camera=document.getElementById("webcam_movie");
	camera.cameraContinue();
	}